package com.huarui.initial.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import com.huarui.initial.action.InitialAction;
import com.huarui.initialItem.model.InitialItem;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;

public class InitialUtil {
	/**
	 * 将字符串已多个分隔符拆分为数组,调用Apache commons lang 中的方法
	 * 
	 * <pre>
	 *    Example:
	 *     String[] arr = StringUtils.split(&quot;a b,c d,e-f&quot;, &quot; ,-&quot;);
	 *     System.out.println(arr.length);//输出6
	 * </pre>
	 * 
	 * @param str
	 *            目标字符串
	 * @param separatorChars
	 *            分隔符字符串
	 * @return 字符串数组
	 */
	public static String[] split(String str, String separatorChars) {
		return StringUtils.split(str, separatorChars);
	}

	/**
	 * 将对象数组的每一个元素分别添加到指定集合中,调用Apache commons collections 中的方法
	 * 
	 * @param collection
	 *            目标集合对象
	 * @param arr
	 *            对象数组
	 */
	@SuppressWarnings("unchecked")
	public static void addToCollection(Collection collection, Object[] arr) {
		if (null != collection && null != arr) {
			CollectionUtils.addAll(collection, arr);
		}
	}

	public static String stringFilter(String str) {
		String regEx = "[*]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.replaceAll("").trim();
	}
	
	public static boolean isSenSymbol(String str){
		String regEx = "[*]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.find();
	}
	public static boolean isNum(String str){
		String regEx = "^[0-9]*$";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.find();
	}
	public static String test() throws Exception{
		  ActionContext context=ActionContext.getContext();
		  ActionInvocation invocation=context.getActionInvocation();
		  ActionProxy proxy=invocation.getProxy();
		  String config=proxy.getNamespace();
		  System.out.println(config);

		  return "success";
	} 
	
	public static BigDecimal getAmout(BigDecimal retailPrice,Integer quantity){
		if(retailPrice!=null&&quantity!=null){
			return retailPrice.multiply(new BigDecimal(quantity));
		}else{
			return new BigDecimal(0);
		}
	}
	public static BigDecimal calAmout(InitialItem item){
		BigDecimal result=BigDecimal.ZERO;
		if(item.getCost()!=null&&item.getQuantity()!=null){
			result=item.getCost().multiply(new BigDecimal(item.getQuantity()));
		}
		return result;
	}
	public static void main(String[] args) {
		Integer a=150;
		Integer b=150;
		System.out.println(a.equals(b));
	}
	
}
